import sys
from python_ai.common.xcommon import *
import tensorflow as tf

print(tf.__version__)

a = tf.reshape(tf.range(1, 12+1, dtype=tf.float32), [3, 4])
# tf.print(a)
tf.print(a, output_stream=sys.stdout)

sep('foldr "-"')
b = tf.foldr(lambda a, x: a-x, a)
tf.print(b, output_stream=sys.stdout)

sep('foldr +')
b = tf.foldr(lambda a, x: a+x, a)
tf.print(b, output_stream=sys.stdout)

sep('foldr -, init 0')
b = tf.foldr(lambda a, x: a-x, a, initializer=tf.zeros([1, 4], dtype=tf.float32))
tf.print(b, output_stream=sys.stdout)

sep('foldr -, init None')
b = tf.foldr(lambda a, x: a-x, a, initializer=None)
tf.print(b, output_stream=sys.stdout)

sep('foldl "-"')
b = tf.foldl(lambda a, x: a-x, a)
tf.print(b, output_stream=sys.stdout)
